﻿using Sunny.UI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using WinKeyBoard.Helpers;

namespace WinKeyBoard.Pages
{
    public partial class FrmSettings : UIForm
    {
        public FrmSettings()
        {
            InitializeComponent();
        }

        //初始化
        private void FrmSettings_Load(object sender, EventArgs e)
        {
            GetCurrentTheme();

            //开机自启动
            string autoStartStr = IniHelper.ReadOrWrite(Sections.AutoStart, "0", "是否开机自启动");
            //chkAutoStart.Checked = autoStartStr == "0" ? false : true;

            //启动后是否停靠边缘
            string startDockStr = IniHelper.ReadOrWrite(Sections.StartDock, "0", "启动后是否停靠边缘");
            //chkStartDock.Checked = startDockStr == "0" ? false : true;
        }
        
        /// <summary>
        /// 获取当前主题
        /// </summary>
        public void GetCurrentTheme()
        {
            var theme = IniHelper.ReadValue(Sections.Theme);
            string[] a = theme.Split(',');
            pnlCurrentTheme.FillColor = pnlCurrentTheme.RectColor = Color.FromArgb(Convert.ToInt32(a[0]), Convert.ToInt32(a[1]), Convert.ToInt32(a[2]));
            pnlCurrentTheme.ForeColor = Color.White;

            var fillColor = pnlCurrentTheme.FillColor;
            lblRgb.Text = $"{fillColor.R},{fillColor.G},{fillColor.B}";

        }

        #region 主题颜色
        /// <summary>
        /// 设置主题
        /// </summary>
        /// <param name="sender"></param>
        private void SetTheme(object sender)
        {
            var panel = (UIPanel)sender;
            var fillColor = panel.FillColor;
            UIStyles.InitColorful(fillColor, Color.White);

            pnlCurrentTheme.FillColor = pnlCurrentTheme.RectColor = fillColor;
            pnlCurrentTheme.ForeColor = Color.White;
            lblRgb.Text = $"{fillColor.R},{fillColor.G},{fillColor.B}";

            IniHelper.WriteValue(Sections.Theme, lblRgb.Text);
        }
        private void pnlTheme1_Click(object sender, EventArgs e)
        {
            SetTheme(sender);
        }

        #endregion

    }
}
